package playback;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.Arrays;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;


public class MidiTest {

	public static void main(String[] args) throws Exception {
		File f = new File("C:\\Users\\Layne\\Music\\Relative.wav");
		Clip ac = AudioSystem.getClip();
		AudioInputStream ais = AudioSystem.getAudioInputStream(f);	
		
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		int read;
		byte[] buff = new byte[1024];
		while ((read = ais.read(buff)) > 0)
		{
		    out.write(buff, 0, read);
		}
		out.flush();
		byte[] audioBytes = out.toByteArray();
		byte[][] doub = ClipManager.split(audioBytes, 1000);
		byte[] play = ClipManager.addSilenceGap(AudioSystem.getAudioFileFormat(f).getFormat(), 1000, doub[0], doub[1]).getBytes();
		
		Clip c = AudioSystem.getClip();
		c.open(AudioSystem.getAudioFileFormat(f).getFormat(), play, 0, play.length);
		c.start();
		Thread.sleep((long)(c.getFrameLength()*c.getFormat().getFrameRate()*1000));
		c.stop();
	}

}
